Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

174
Visualizações
How to parse response [object object]

The request is being sent from onclick of href=url. When this url is hit, I am returning data from server to client as a query string.

res.redirect("/#blog_post_details/?dataUrl="+response[0].attributes);

And when I print using:

var posts = DataMixin.getParameterByName(dataUrl);
console.log('posts', posts); //I get [Object, Object]

I also tried with JSON.Stringify: console.log('posts', JSON.Stringify(posts)); which prints the same with quotes "[Object,Object]"

Function to return query string:

getParameterByName: function (name, url) {
    if (!url) {
      url = window.location.href;
    }
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}

However, I am able to print response data on server:

{ created_at: '4/3/2017, 1:23:28 AM',
  details: 'jjj',
  id: 136,
  post_id: '1491162808010',
  title: 'Basic Syntax and Tag declaration',
  url: 'basic_syntax_and_tag_declaration',
  userImage: 'assets/img/spiritual-icon4.png',
  username: 'k999@gmail.com' }

Note: I am using expressjs with nodejs

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

[Object, Object] is the value you are sending. Parsing it won't do any good, there is nothing useful to parse.

You need to fix how you are sending the data.

Encoding it as JSON is one approach:

var values = response[0].attributes;
var json_values = JSON.stringify(values);
var url_safe_json_values = encodeURIComponent(json_values);
res.redirect("/#blog_post_details/?dataUrl=" + url_safe_json_values

then you parse the JSON (with JSON.parse not JSON.stringify (which does the opposite of parsing!)) at the other end.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda